package com.chen.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chen.pojo.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author chenchao
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from user where open_id = #{openid}")
    User getOpenid(@Param(value = "openid") String openid);


    //    积分加5
    @Update("update user set points=points+5 where id=#{id}")
    int addPoints(@Param("id") int id);

    @Update("update user set points=points+ #{points} where id=#{id}")
    int updatePoint(@Param("points") Integer points, @Param("id") int id);


    @Select("select *from user where id=#{id}")
    User selectOne1(@Param("id") int id);


//    一对多查询
    @Select("select *from user where id=#{id}")
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "points", property = "points", jdbcType = JdbcType.BIGINT)
    })
    List<User> list();

    @Select("select count(*) as userCount from user ")
    int UserCounts();


}
